package com.example.demo.contorller;

import com.example.demo.Bean.Result;
import com.example.demo.Bean.Student;
import com.example.demo.service.ExperimentStuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class ExperimentStuController {

    @Autowired
    ExperimentStuService experimentStuService;

    @RequestMapping("/searchExperimentStu")
    @CrossOrigin
    public Result searchExperimentStu(String name,String studentUid,Integer pageSize,Integer pageNum){
        try {
            return experimentStuService.searchExperimentStu(name, studentUid, pageNum, pageSize);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }

    @RequestMapping("/getTotalExperimentStuNum")
    @CrossOrigin
    public Result getTotalExperimentStuNum(String studentUid){
        try {
            return experimentStuService.getTotalExperimentStuNum(studentUid);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }

    @RequestMapping("/getStatus")
    @CrossOrigin
    public Result getStatus(String studentUid,Integer experimentId){
        try {
            return experimentStuService.getStatus(studentUid, experimentId);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }

    /**
     * 作废
     * @param pageNum
     * @param pageSize
     * @param studentUid
     * @return
     */
    @RequestMapping("/getExperimentStuPage")
    @CrossOrigin
    public Result getExperimentStuPage(Integer pageNum,Integer pageSize,String studentUid){
        try {
            return experimentStuService.getExperimentStuPage(pageNum, pageSize, studentUid);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }

    @RequestMapping("/getReportCode")
    @CrossOrigin
    public Result getReportCode(String studentUid,Integer experimentId){
        try {
            return experimentStuService.getReportCode(studentUid, experimentId);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }

    @RequestMapping("/getReportStu")
    @CrossOrigin
    public Result getReportStu(String studentUid,Integer experimentId){
        try {
            return experimentStuService.getReportStu(studentUid, experimentId);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }

    @RequestMapping(path = "/uploadReport",method = RequestMethod.POST)
    @CrossOrigin
    public Result uploadReport(MultipartFile file,Integer experimentId, Student student){
        try {
            return experimentStuService.uploadReport(file, experimentId, student);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.toString());
        }
    }

}
